<div id="manager">
    <div>
        <div id="bg-title1"><img src="/images/bg-title1.jpg" alt=""></div>
        <div id="bg-title2"><img src="/images/icon-title.jpg" alt="" style="margin-right: 8px;">Sửa thành viên</div>
        <div id="bg-title3"><img src="/images/bg-title3.jpg" alt=""></div>
        <div class="clearfloat"></div>
    </div>

    <div id="content">
        <div class="area-button">
            <div class="area-button1">
                <a href="javascript:;" onclick="update(document.getElementsByName('chk_group'), document.getElementById('group_id_list'));this.disabled = true;" class="button">Cập nhật</a>
            </div>

            <div class="clearfloat"></div>
        </div>

        <div>
            <div class="area-content1">
                <form name="frmEditUser" method="post" action="/admin/edit?id=<?php echo $user['id'] ?>">
                <div>
                    <div class="form">
                            <div class="form1">Tên truy cập</div>
                        <div class="form2">
                            <b><?php echo $user['name'] ?></b>
                        </div>
                        <div class="clearfloat"></div>
                    </div>

                    <div class="form">
                            <div class="form1">Tên đầy đủ</div>
                        <div class="form2">
                            <input name="fullname" style="width: 300px;" class="style-form" type="text" value="<?php echo isset($_POST['fullname']) ? $_POST['fullname'] : '' ?>">
                            <?php if(isset($error['fullname'])): ?>
                            <div class="error"><?php echo $error['fullname'] ?></div>
                            <?php endif; ?>
                        </div>
                        <div class="clearfloat"></div>
                    </div>
                    <div class="form">
                            <div class="form1">Mật khẩu truy cập</div>
                        <div class="form2">
                            <input name="password" style="width: 300px;" class="style-form" type="password" value="">
                            <?php if(isset($error['password'])): ?>
                            <div class="error"><?php echo $error['password'] ?></div>
                            <?php endif; ?>
                        </div>
                        <div class="clearfloat"></div>
                    </div>
                    <div class="form">
                            <div class="form1">Email</div>
                        <div class="form2">
                            <input name="email" style="width: 300px;" class="style-form" type="text" value="<?php echo isset($_POST['email']) ? $_POST['email'] : '' ?>">
                            <?php if(isset($error['email'])): ?>
                            <div class="error"><?php echo $error['email'] ?></div>
                            <?php endif; ?>
                        </div>
                        <div class="clearfloat"></div>
                    </div>

                    <div class="form">
                        <div class="form1">Nhóm</div>
                        <div class="form2">
                            <input type="hidden" id="group_id_list" name="group_id_list" value="">
                            <table>
                                <tr><?php
                                $k =0;
                                foreach($groups AS $group){
                                    $check = "";
                                    for($i =0; $i < sizeof($arrGroup); $i ++){
                                        if($arrGroup[$i]['group_id'] == $group['id']){
                                            $check = "checked";
                                        }
                                    }?>
                                    <td>
                                        <input onclick="_onclick(document.getElementsByName('chk_group'), this.value);" name="chk_group" type="checkbox" <?=$check?> value="<?=$group['id']?>"/><?=$group['name']?>&nbsp;
                                    </td><?
                                    if($k %2 != 0){
                                        echo '</tr><tr>';
                                    }
                                    $k ++;
                                }
                                if($k %2 == 0){
                                    echo '</tr>';
                                }?>
                            </table>
                        </div>
                        <div class="clearfloat"></div>
                    </div><?php
                    $display = 'none';
                    if($user['group_id'] == 2){
                        $display = 'block';
                    }
                    ?>
                    <div class="form" id="parent_cp" style="display:<?=$display?>;">
                        <div class="form1">CP cha</div>
                        <div class="form2">
                            <table><?php
                                if (isset ($arrParentCP)) {?>
                                    <tr><?php
                                    $i =0;
                                    foreach($arrParentCP AS $parent){
                                        $check = "";
                                        if($parent['id'] == $user['parent_id']){
                                            $check = "checked";
                                        }?>
                                        <td>
                                            <input name="rdo_parent_cp" id="rdo_parent_cp" <?=$check?> type="radio" value="<?=$parent['id']?>"/><?=$parent['name']?>&nbsp;
                                        </td><?php
                                        if($i %2 != 0){
                                            echo '</tr><tr>';
                                        }
                                        $i ++;
                                    }
                                    if($i %2 == 0){
                                        echo '</tr>';
                                    }
                                }?>
                            </table>
                        </div>
                        <div class="clearfloat"></div>
                    </div>
                </div>
                    <script type="text/javascript">
                        function update(group_id_item, hdn_item){
                            var k =0;
                            for(i =0; i < group_id_item.length; i ++){
                                if(group_id_item[i].checked){
                                    k ++;
                                    hdn_item.value += group_id_item[i].value + '!#!';
                                }
                            }
                            if(k > 0){
                                document.forms[0].submit();
                            }else{
                                alert('Chua chon nhom cho nguoi dung!');
                                return;
                            }
                            
                        }
                        function _onclick(group_id_item, item_value){
                            var check = 0;
                            for(i =0; i < group_id_item.length; i ++){
                                if(group_id_item[i].value != item_value){
                                    group_id_item[i].checked = false;
                                }
                                if(group_id_item[i].checked){
                                    check = group_id_item[i].value;    
                                }
                            }
                            try{
                                if(check == 2){                                        
                                    document.getElementById('parent_cp').style.display = "block";
                                }else{
                                    document.getElementById('parent_cp').style.display = "none";
                                    var rdo_parent_cp = document.getElementsByName('rdo_parent_cp');
                                    for(j =0; j < rdo_parent_cp.length; j ++){
                                        rdo_parent_cp[j].checked = false;
                                    }
                                }
                            }catch(e){;}
                        }
                    </script>
                </form>
                <div class="clearfloat"></div>
           </div>
        </div>
   </div>
</div>
<div class="clearfloat"></div>
